package com.itheima.controller;

import com.itheima.common.PageResult7;
import com.itheima.common.Simple;
import com.itheima.entity.SubjectsDirectorys;
import com.itheima.entity.SubjectsDirectorysDto;
import com.itheima.entity.SubjectsDto;
import com.itheima.service.SubjectsDirectorysService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author cfr
 * @date 2022/1/10
 * @TIME:15:29
 */
@RestController
@RequestMapping("/directorys")
public class SubjectsDirectorysController {
    @Autowired
    private SubjectsDirectorysService subjectsDirectorysService;

    @GetMapping
    public PageResult7 findPage(Long page, Long pagesize, String directoryName, Integer state, Integer subjectID) {
        return subjectsDirectorysService.findPage(page, pagesize, directoryName, state, subjectID);
    }

    @PostMapping
    public String add(@RequestBody SubjectsDirectorys subjectsDirectorys) {
        subjectsDirectorys.setCreatorID(2);
        return subjectsDirectorysService.add(subjectsDirectorys);
    }

    @PostMapping("/{id}/{state}")
    public String state(@PathVariable Integer id, @PathVariable Integer state) {
        return subjectsDirectorysService.state(id, state);
    }

    @PutMapping("/{id}")
    public String modify(@RequestBody SubjectsDirectorys subjectsDirectorys) {
        return subjectsDirectorysService.modify(subjectsDirectorys);
    }

    @DeleteMapping("/{id}")
    public String deleteById(@RequestBody SubjectsDirectorysDto subjectsDirectorysDto) {
        return subjectsDirectorysService.delete(subjectsDirectorysDto);
    }

    @GetMapping("/{id}")
    public SubjectsDirectorysDto fingById(@PathVariable Integer id) {
        return subjectsDirectorysService.findById(id);
    }

    @GetMapping("/simple")
    public List<Simple> findDirectorys(Integer subjectID) {
        List<Simple> simpless = subjectsDirectorysService.findDirectorys(subjectID);
        return simpless;
    }
}
